﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;
using System.Data.SqlClient;
using System.Diagnostics;

namespace WindowsFormsApp3
{
    public partial class dlck : Form
    {
        public dlck()
        {
            InitializeComponent();
        }
        private void insertData(SqlConnection Sqlconn)
        {
            String sqlInsert = "insert into xx(userName,userID,password) values(@NAME,@ID,@PASSWORD)";

            SqlCommand cmdInsert = new SqlCommand(sqlInsert, Sqlconn);
            SqlParameter para1 = new SqlParameter("@NAME", "liu");
            cmdInsert.Parameters.Add(para1);
            SqlParameter para2 = new SqlParameter("@ID", "007");
            cmdInsert.Parameters.Add(para2);
            SqlParameter para3 = new SqlParameter("@PASSWORD", "13502296");
            cmdInsert.Parameters.Add(para3);


            //对连接执行 Transact-SQL 语句并返回受影响的行数
            int res = cmdInsert.ExecuteNonQuery();
            MessageBox.Show(res == 0 ? "插入数据失败！" : "插入数据成功！");

        }
        private void dlck_Load(object sender, EventArgs e)
        {
            string str1 = System.Environment.CurrentDirectory;
            Console.WriteLine(str1);
            string path = "../../config/info.ini"; //@"C:\Users\Administrator\source\repos\ConsoleApp1\config\info.ini";
            string connectStr = "Data Source=.;Initial Catalog=cmxx;Integrated Security=True";
            //建立连接对象
            SqlConnection Sqlconn = new SqlConnection(connectStr);
            //打开连接
            Sqlconn.Open();
            //insertData(Sqlconn);
            Sqlconn.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string str1 = System.Environment.CurrentDirectory;
            string connectStr = "Data Source=.;Initial Catalog=cmxx;Integrated Security=True";
            //建立连接对象
            SqlConnection Sqlconn = new SqlConnection(connectStr);
            //打开连接
            Sqlconn.Open();
            insertData(Sqlconn);
            
            Sqlconn.Close();
            MessageBox.Show("注册成功");
            this.Hide();
            Form1 form1 = new Form1();
            form1.Show();
        }
    }
}
